home *** CD-ROM | disk | FTP | other *** search
- Introduction
- This document explains how to build a control simulation under
- GAF. A brief description of basic concept and steps to build a
- simulation is presented. Then, a simple example of water heater
- control is used to explore the basics of GAF.
-
- What is a segment
- A segment is a text file contains:
- · configuration information
- · variable declarations (IN, OUT, INOUT, and LOCAL)
- · symbol (fuzzy membership set) declarations
- · condition to enable the segment
- · initialization
- · reset
- · pre-processing
- · post-processing
- · fuzzy rules
-
- Just like dividing the system into several manageable portions,
- GAF allows a control system to be divided into segments. For
- example, a simulated control environment under GAF may have these
- different segments:
- · control segment(s)
- · reference calculation and supporting segment(s)
- · simulation (or feedback) segment(s)
- · evaluation segment
- The feedback and evaluation segments are used for simulation and
- adaptation.
-
- Segment Construction
- To construct a segment is quite similar to construct a simple
- program. Please refer to FCL.DOC for detail syntax and *.gaf,
- *.fbk, *.sim, and *.evl files for examples. Note that these
- steps can be in any order to your convience. These steps are:
-
- 1. Define variables
- All variables must be declared before they can be used either
- by fuzzy rules or any statements in a segment. There are four
- types of variables: IN, OUT, INOUT, and LOCAL.
-
- IN Variables
- IN variables are used as "references" in this segment. IN
- variables must be in one of the categories:
- · calculated by other segment (as OUT or INOUT)
- · an input from real world, i.e. a sensor, in the simulation this
- input may be an OUT from a feedback segment.
- · application constants, can be modified through interactive
- interface during simulation
-
- OUT variables
- OUT variables are calculated outputs by this segment. OUT
- variables are either:
- · an output signal to a real world device
- · be used by other segment as IN variables
- · for diagnostic purpose
- · evaluation result
- Note that for each output variable, there must be only one
- segment declares it as an OUT or INOUT variable. If more
- than one segment declares an output variable as OUT or INOUT,
- the result is undefined.
-
- INOUT variables
- INOUT variables are both referenced and modified by this
- segment, i.e., it is the combination of both IN and OUT
- variables. Normally INOUT variables are referenced by this
- segment and other segments.
-
- All of the IN, OUT, and INOUT variables are visible to other
- segments, i.e. other segments can use this segment's OUT as its
- IN.
-
- LOCAL variables
- LOCAL variables are local to this segment. Normally, local
- variables are used to store temporary values so it can be
- used by fuzzy rules or other statements within the segment.
-
-
- 2. Define fuzzy membership
- The second step would be define the fuzzy membership set. GAF
- uses four points for each set. In general, fuzzy sets should
- be defined for each variable, either in out or local, that is
- used in the fuzzy rules. For example, as described in the
- following figure. A simple way to define membership sets for a
- variable is to equaly divide the range of the variable into six
- to obtain five sets - very low (VL), low (LO), medium (M), high
- (HI), and very high (VH).
-
- ----- - - - -----
- \ / \ / \ / \ /
- \ / \ / \ / \ /
- X X X X
- / \ / \ / \ / \
- / \ / \ / \ / \
- +-----+-----+-----+-----+-----+-----+
- -1 -0.67 -0.33 0 0.33 0.67 1
- | very low | medium | very high |
- | low | high |
-
- As the above diagram shows these five membership sets are
- symmatrically divided. Then, use these membership sets for the
- starting point.
-
- SYMBOL very_low (-1.00, -1.00, -0.67, -0.33, 1.0)
- SYMBOL low (-0.67, -0.33, -0.33 0, 1.0)
- SYMBOL medium (-0.33, 0, 0, 0.33, 1.0)
- SYMBOL high ( 0, 0.33, 0.33, 0.67, 1.0)
- SYMBOL very_high ( 0.33, 0.67, 1, 1, 1.0)
-
-
- 3. Translate ideas into fuzzy rules
- Defining fuzzy rules is quite straight forward. Basically,
- this step is simply converting an imprecise idea of how things
- should work into fuzzy rules. For example, based on common
- sense to control a water heater, a simple rule may be like:
- "if water usage is heavy and water is cold,
- then the gas fuel valve to heat the tank must be full open"
- This idea can turn into a rule like:
- IF water_usage IS heavy AND water IS cold
- THEN fuel_valve IS full_open
- Where water_usage and water are IN variables, fuel_valve is an
- OUT variable; heavy, cold, and full_open are membership sets
- defined for corresponding variables. Note that all variables
- that are part of "THEN" statement must be declared as OUT or
- INOUT.
-
- Please refer to step 6 for more information.
-
-
-
- 4. Initializes the segment
- Next step is to define what do you want the segment to be
- initialized. In general, the initialization of a segment is to
- initialize all outputs (OUT and INOUT variables) and its local
- variables. The initialization will be executed when the system
- "comes up" (i.e., the first time it runs the segment) or
- requested from user interactive interface. The initialization
- formulas and other processing formulas are arranged like this:
-
- what's in the text remarks
- ------------------- ----------------------------------------
- INITIALIZATION must have this key word
- ... ; statements for initialization
- each statement must end with ';'
- RESET optional key word for reset processing
- ... ; optional statements for reset processing
- PRE_PROCESSING optional key word for pre-processing
- ... ; optional statements for pre-processing
- POST_PROCESSING optional key word for post-processing
- ... ; optional statements for post-processing
- END; must have this key word (with ';')
-
- Note that INITIALIZATION must be the first statemant and END
- must be the last statement. For example, for the above water
- heat control, the segment should initialize the fuel_valve to
- close.
-
- INITIALIZATION
- fuel_valve = 0;
- PRE_PROCESSING
- ...
- END;
-
-
- 5. Reset processing
- Similar to initialization, the reset processing is to reset the
- segment when the segment is disabled. The reset processing is
- only necessary when it is different from the initialization.
-
-
- 6. Pre-processing and post-processing
- The pre-processing is a set of statements to be calculated
- before the fuzzy rules are inferenced. The post-processing is
- a set of statements to be calculated after the fuzzy rules are
- inferenced. The formulas can be used for calculating
- references or other simple mathematical models. Pre-processing
- is calculated before any fuzzy rule been evaluated, so the
- results of these formulas may be used by fuzyy rules to
- inference the result.
-
-
- 7. Segment enable condition
- Now, it's time to decide how and when should this segment be
- enabled. The enable condition determines whether the segment
- shoud run or not. If enable condition is not specified GAF
- treats the segment as enabled all the time.
-
-
-
- Example: Water Heater Temperature Control
-
- Let's use a simple water heater control to illustrate these steps
- in constructing a control segment. First, let's explain the
- simple device that we are going to control.
-
- The water heater
- The following diagram shows the physical layout of the water
- heater.
-
- temperature sensor
- !
- !
- /-------!-------\ valve
- high | ! <=======x======= water in
- sensor----x ! |
- | ! |
- | ! |
- | ! |
- | ! |
- | ! |
- | ! |
- | ! |
- | ! | low
- | ! x----sensor
- water valve | |
- out <=====x====== |
- \---------------/
- ^^^^^^^^^ burner
- !
- !<======x=======fuel
- valve
-
-
- As shown in the diagram, these are the major devices for the
- water heater and can be used by the controller to control the
- water temperature.
- 2 water valves: in & out
- 2 water sensors: high & low
- 1 water temperature sensor
- 1 fuel valve
-
- Let's also assume that the heater can heat a full tank of water
- up one degree per second with max gas fuel. The water tank can
- be drained in 100 seconds with full-open water out valve.
-
- To simplify the problem, let's split the controller into two
- part: a water temperature control and a water volume control.
- The reason, besides cover this example in few pages, is to
- isolate the temperature controller from the water controller.
- So, inside the temperature controller we can assume that the
- water volume is a constant.
-
-
- Step 1: Define variables
- Since we are only controling the water temperature, it is quite
- easy to identify the output of the controller, i.e., the fuel
- valve. The inputs to this controller are: the water
- consumption (from the valve of water out), the water
- temperature from the sensor. Also, there should be a target
- temperature as an input to this controller. After identify
- these variables, now we can find out their range and declare
- these variables.
- IN Target_Temp (32, 212) ! target temperature
- IN Temperature (32, 212) ! measured temperature
- IN Water_out (0, 1) ! 0 - 1 input from the water out valve
- OUT Gas_valve (0, 10) ! 0 - 10 volts output to the fuel valve
-
-
-
-
- Step 2: Define Pre-processing and Initialization
- Because we only care about the temperature error, which is the
- difference between the reference and the measured water
- temperature. So, we can use the pre-processing to calculate
- the temperature error before inference the fuzzy rules. In
- order to do this, a new local variable has to be put in:
- LOCAL Temp_error (-180, 180)
- Then the pre-processing and initialization is:
- INITIALIZATION
- Gas_valve = 0; ! turn off the valve
- Temp_error = 0; !
- PRE_PROCESSING
- Temp_error = Temperature - Target_Temp ;
- END;
-
-
-
-
- Step 3: Define Fuzzy Membership
- Let's start defining membership set by using the simple method
- discussed. Note that for the water consumption, and gas valve
- only the right half (> 0) is used.
-
- The Water_out variable divided into 5 bands, i.e., very heavy,
- heavy, medium, light, and zero comsumption. The result would
- be:
-
- - - - - -------
- \ / \ / \ / \ /
- \ / \ / \ / \ /
- X X X X
- / \ / \ / \ / \
- / \ / \ / \ / \
- +-----+-----+-----+-----+-----+
- 0 0.2 0.4 0.6 0.8 1.0
-
- ! below low high above truth
- SYMBOL Zero OF Water_out ( 0.0, 0.0, 0.0, 0.2, 1.0)
- SYMBOL Light OF Water_out ( 0.0, 0.2, 0.2, 0.4, 1.0)
- SYMBOL Medium OF Water_out ( 0.2, 0.4, 0.4, 0.6, 1.0)
- SYMBOL Heavy OF Water_out ( 0.4, 0.6, 0.6, 0.8, 1.0)
- SYMBOL VeryHeavy OF Water_out ( 0.6, 0.8, 1.0, 1.0, 1.0)
-
- The Temp_error variable is divided into these five membership
- sets (with extended VeryHot and VeryCold):
-
- ------- - - - -----
- \ / \ / \ / \ /
- \ / \ / \ / \ /
- X X X X
- / \ / \ / \ / \
- / \ / \ / \ / \
- +-..--+-----+-----+-----+-----+--..-+
- -180 -40 -20 0 20 40 180
-
- ! below low high above truth
- SYMBOL VeryCold OF Temp_error (-180.0, -180.0, -40.0, -20.0, 1.0)
- SYMBOL Cold OF Temp_error ( -40.0, -20.0, -20.0, 0.0, 1.0)
- SYMBOL OnTarget OF Temp_error ( -20.0, 0.0, 0.0, 20.0, 1.0)
- SYMBOL Hot OF Temp_error ( 0.0, 20.0, 20.0, 40.0, 1.0)
- SYMBOL VeryHot OF Temp_error ( 20.0, 40.0, 180.0, 180.0, 1.0)
-
-
- The Gas_valve variable:
-
- - - - - -------
- \ / \ / \ / \ /
- \ / \ / \ / \ /
- X X X X
- / \ / \ / \ / \
- / \ / \ / \ / \
- +-----+-----+-----+-----+-----+
- 0 2 4 6 8 10
-
- ! below low high above truth
- SYMBOL Off OF Gas_valve ( 0.0, 0.0, 0.0, 2.0, 1.0)
- SYMBOL VeryLow OF Gas_valve ( 0.0, 2.0, 2.0, 4.0, 1.0)
- SYMBOL Low OF Gas_valve ( 2.0, 4.0, 4.0, 6.0, 1.0)
- SYMBOL High OF Gas_valve ( 4.0, 6.0, 6.0, 8.0, 1.0)
- SYMBOL VeryHigh OF Gas_valve ( 6.0, 8.0, 10.0, 10.0, 1.0)
-
-
-
-
- Step 4: Translate Ideas Into Fuzzy Rules
- Using common sense to implement rules, such as turn this idea
- if the water consumption is very heavy and the water is very
- cold then full open the gas fuel valve
- into a rule
- IF Water_out IS VeryHeavy AND Temp_error IS VeryCold
- THEN Gas_valve IS VeryHigh
-
- There is an easy approach for this simple controller - by
- filling a table. As shown in the following table, this rule's
- output VeryHigh is in the top left cell. The rest of the table
- can be filled in based on this kind of common ideas.
-
- VeryHeav Heavy Medium Light Zero
- -------- -------- -------- -------- --------
- VeryCold VeryHigh VeryHigh VeryHigh VeryHigh VeryHigh
- Cold VeryHigh VeryHigh VeryHigh High High
- OnTarget VeryHigh High Low VeryLow Off
- Hot High Low VeryLow Off Off
- VeryHot Low VeryLow Off Off Off
-
-
- Note that some may argue that the "table filling" approach can
- be applied not just simple controls but also complex controls
- by pairing two inputs and one output. But a system built with
- this approach (without optimization) may require intense CPU
- power and contain extremely complicated rule set.
-
-
-
-
- Step 5: Segment Enable Condition
- In order to avoid unnecessary sensitive reaction from the
- controller, a hysteresis null band can be put in to enable or
- disable the control segment. As in the example file
- heattank.sim, the output variable Heating is calculated based
- on a hysteresis null band. So, we can add an ENABLE condition
- to achieve this:
- ENABLE = Heating;
- This will disable the segment within the hysteresis null band.
- When the segment is disabled we want shut off the output
- Gas_valve, because this is identical to the initialization, so
- it's not necessary to define the RESET processing.
-
-
-
-
- Results
- Please refer to the accompany files heattank.x01 and
- heattank.x02 for the result of this excercise.
- Note:
- 1. The Temp_error is calculated outside this control segment.
- 2. The symbol Off and VeryHigh defined for Gas_valve have special
- "center" values, which define the output center value for these
- fuzzy sets.
- 3. The .x02 has incorporated some simplifications of the rules
- (from the above rule table).
-
- The heattank.fbk emulates the reaction of the water tank with
- simple calculation based on the input/output energy. A few
- rules are added to introduce some heat loss and non-linear
- portion of the system.
-